package com.hxkcloud.patient.views;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.YjhApplication;


/**
 * @ClassName: MyToast.java
 * @Description:自定义Toast
 */

public class MyToast extends Toast {

    private static final String TAG = "MyToast";

    private TextView tv_toast;

    private static MyToast myToast;

    public static MyToast geToast() {
        if (myToast == null) {
            myToast = new MyToast(YjhApplication.getInstance());
        }
        return myToast;
    }

    public MyToast(Context context) {
        super(context);

        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_toast, null);
        tv_toast = (TextView) view.findViewById(R.id.tv_toast);
        setDuration(Toast.LENGTH_SHORT);
        setGravity(Gravity.CENTER, 0, 0);
        setView(view);
    }

    public void setMsg(String msg) {
        setDuration(Toast.LENGTH_SHORT);
        tv_toast.setText(msg);
        show();
    }

    public void setMsg(int msg) {
        setDuration(Toast.LENGTH_SHORT);
        tv_toast.setText(msg);
        show();
    }

    public void setLongMsg(String msg) {
        setDuration(Toast.LENGTH_LONG);
        tv_toast.setText(msg);
        show();
    }

    public void setLongMsg(int msg) {
        setDuration(Toast.LENGTH_LONG);
        tv_toast.setText(msg);
        show();
    }

    public TextView getMsgText() {
        return tv_toast;
    }

}
